import os

# 方法一
count_total = 0


def folder_size(files):
    global count_total
    if os.path.isfile(files):
        count_total += os.path.getsize(files)
    elif os.path.isdir(files):
        for fil in os.listdir(files):
            new_fp = os.path.join(files, fil)
            folder_size(new_fp)
    else:
        print("路径无效")


folder_size(os.getcwd())

print(count_total)


# 方法二


def folder_size2(files):
    count_total2 = 0
    for fil in os.listdir(files):
        new_p = os.path.join(files, fil)
        if os.path.isfile(new_p):
            count_total2 += os.path.getsize(new_p)
        else:
            count_total2 += folder_size2(new_p)
    return count_total2


print(folder_size2(os.getcwd()))
